package com.sdksoft.readcard

import com.csht.constants.Constant
import com.csht.enums.ReadCardType
import com.csht.enums.StatusCode
import com.csht.listener.InitListener


class SamActivity : BaseIDCardActivity(), InitListener {

    private var initSuccess = false

    override fun initView() {
        super.initView()
        setTitleText("读取身份证、居住证")
        readSettingBuilder.buildReadCardType(ReadCardType.SAM_USB)
        readCardManager.readCardInit(this)
    }

    override fun onResponse(code: Int, msg: String) {
        mHandler.post {
            if (code == StatusCode.ININ_ING.code) {
                appendLog("初始化中$code，$msg")
            } else if (code != StatusCode.ININ_OK.code) {
                initSuccess = false
                if (Constant.READCARD_TYPE == ReadCardType.SAM_USB) {
                    readSettingBuilder.buildReadCardType(ReadCardType.SAM_SERIALPORT)
                    readCardManager.readCardInit(this)
                } else {
                    appendLog("初始化失败$code")
                }
            } else {
                initSuccess = true
                appendLog("初始化成功")
                appendLog("\n$msg")
                readCardManager.readCardStart(this)
            }
        }
    }
}